<?php
/**
 * 优盒配置数据获得操作
 */
namespace Admin\Controller;
use Admin\BaseController;
use Think\Page;
import('ThirdLib.Snoopy',WEB_ROOT);
import('SoeLib.UHCore',WEB_ROOT);
/*Ajax异步获取数据Action*/
class UHDataController extends BaseController{

	/**
	 * 商品列表页
	 * Author: shijy
	 */
	public function index(){
		$goodsM = M("cfg_uh_goods_info",null,DB_MAIN_CFG);
		import("ORG.Util.Page");
		$count = $goodsM->count();
		$Page = new Page($count,10);
		$show = $Page->show(); // 分页显示输出
		$list = $goodsM->join('left join cfg_xy_goods_sku on cfg_uh_goods_info.pGoodsId=cfg_xy_goods_sku.pGoodsId')
			->limit($Page->firstRow.','.$Page->listRows)
			->select();


		$refreshM=M('update_config_log',null,DB_MAIN_CFG);
		$opt=\UHCore::GET_GOODS_INFO;
		$lastModifyTime=$refreshM->where("action='{$opt}'")->getField('addTime');
		$lastModifyTime=$lastModifyTime?getDateTime($lastModifyTime):"从未刷新";
		$this->smarty->assign('lastModifyDateTime',$lastModifyTime);

		$this->smarty->assign('page',$show);
		$this->smarty->assign('list',$list);
		$this->smarty->assign('action','index');
		$this->smarty->display('UHData/index.html');
	}

	//商品编辑页
	public function goodsEdit(){
		$id=I('get.id',0,'int');
		if($id<=0){
			$this->error('请选定商品进行编辑');
		}

		$baseGoodsM=M('cfg_uh_goods_info',null,DB_MAIN_CFG);
		$baseInfo=$baseGoodsM->find($id);
		if(!$baseInfo){
			$this->error('选定商品并不存在');
		}
		$localGoodsM=M('cfg_xy_goods_sku',null,DB_MAIN_CFG);

	}

	//类目列表页
	public function category(){
		$categoryM = M("cfg_uh_goods_category",null,DB_MAIN_CFG);
		import("ORG.Util.Page");
		$count = $categoryM->count();
		$Page = new Page($count,10);
		$show = $Page->show(); // 分页显示输出
		$list = $categoryM->limit($Page->firstRow.','.$Page->listRows)
			->select();

		$refreshM=M('update_config_log',null,DB_MAIN_CFG);
		$opt=\UHCore::GET_GOODS_CATEGORY;
		$lastModifyTime=$refreshM->where("action='{$opt}'")->getField('addTime');
		$lastModifyTime=$lastModifyTime?getDateTime($lastModifyTime):"从未刷新";
		$this->smarty->assign('lastModifyDateTime',$lastModifyTime);

		$this->smarty->assign('page',$show);
		$this->smarty->assign('list',$list);
		$this->smarty->assign('action','category');
		$this->smarty->display('UHData/category.html');
	}

	//类型列表页
	public function types(){
		$typesM = M("cfg_uh_types",null,DB_MAIN_CFG);
		import("ORG.Util.Page");
		$count = $typesM->count();
		$Page = new Page($count,10);
		$show = $Page->show(); // 分页显示输出
		$list = $typesM->limit($Page->firstRow.','.$Page->listRows)->select();

		$refreshM=M('update_config_log',null,DB_MAIN_CFG);
		$opt=\UHCore::GET_TYPES;
		$lastModifyTime=$refreshM->where("action='{$opt}'")->getField('addTime');
		$lastModifyTime=$lastModifyTime?getDateTime($lastModifyTime):"从未刷新";
		$this->smarty->assign('lastModifyDateTime',$lastModifyTime);

		$this->smarty->assign('page',$show);
		$this->smarty->assign('list',$list);
		$this->smarty->assign('action','types');
		$this->smarty->display('UHData/types.html');
	}

	//品牌列表页
	public function brand(){
		$typesM = M("cfg_uh_brands",null,DB_MAIN_CFG);
		import("ORG.Util.Page");
		$count = $typesM->count();
		$Page = new Page($count,10);
		$show = $Page->show(); // 分页显示输出
		$list = $typesM->limit($Page->firstRow.','.$Page->listRows)->select();

		$refreshM=M('update_config_log',null,DB_MAIN_CFG);
		$opt=\UHCore::GET_BRANDS;
		$lastModifyTime=$refreshM->where("action='{$opt}'")->getField('addTime');
		$lastModifyTime=$lastModifyTime?getDateTime($lastModifyTime):"从未刷新";
		$this->smarty->assign('lastModifyDateTime',$lastModifyTime);

		$this->smarty->assign('page',$show);
		$this->smarty->assign('list',$list);
		$this->smarty->assign('action','brand');
		$this->smarty->display('UHData/brand.html');
	}

	//快递列表页
	public function shipping(){
		$shippingM = M("cfg_uh_shipping",null,DB_MAIN_CFG);
		import("ORG.Util.Page");
		$count = $shippingM->count();
		$Page = new Page($count,10);
		$show = $Page->show(); // 分页显示输出
		$list = $shippingM->limit($Page->firstRow.','.$Page->listRows)->select();

		$refreshM=M('update_config_log',null,DB_MAIN_CFG);
		$opt=\UHCore::GET_SHIPPING_METHODS;
		$lastModifyTime=$refreshM->where("action='{$opt}'")->getField('addTime');
		$lastModifyTime=$lastModifyTime?getDateTime($lastModifyTime):"从未刷新";
		$this->smarty->assign('lastModifyDateTime',$lastModifyTime);

		$this->smarty->assign('page',$show);
		$this->smarty->assign('list',$list);
		$this->smarty->assign('action','shipping');
		$this->smarty->display('UHData/shipping.html');
	}


	////////////////////////////以下为实际功能操作////////////////////////////////

	/**
	 * 商品上架
	 * Author: shijy
	 */
	public function goodsUp(){
		$goodId=I('get.id',0,'int');
		if($goodId<=0){
			$this->error('请选择商品再行操作');
		}
		$result=\UHCore::goodsUpDown($id,$opt);
	}

	/**
	 * 商品下架
	 * Author: shijy
	 */
	public function goodsDown(){

	}

	/**
	 *获取商品类目
	 * Author: shijy
	 */
	public function getGoodsCategory(){
		$result=\UHCore::getGoodsCategory();
		if($result[0]==SUCCESS) {
			$this->log('成功');
			$this->success("数据获取成功");
		}else{
			$this->error("数据获取失败");
			$this->log('失败');
		}
	}

	/**
	 *获取商品类型
	 * Author: shijy
	 */
	public function getTypes(){
		$result=\UHCore::getTypes();
		if($result[0]==SUCCESS) {
			$this->success("数据获取成功");
		}else{
			$this->error("数据获取失败");
		}
	}

	/**
	 * 获取物流方式列表
	 * Author: shijy
	 */
	public function getShipping(){
		$result=\UHCore::getShipping();
		if($result[0]==SUCCESS) {
			$this->success("数据获取成功");
		}else{
			$this->error("数据获取失败");
		}
	}


	/**
	 *获取品牌　主函数
	 * Author: shijy
	 */
	public function getBrands(){
		$result=\UHCore::getBrands();
		if($result[0]==SUCCESS) {
			$this->success("数据获取成功");
		}else{
			$this->error("数据获取失败");
		}
	}


	/**
	 * 获取商品列表
	 * Author: shijy
	 */
	public function getGoodsInfo(){
		$result=\UHCore::getGoodsInfo();
		if($result[0]==SUCCESS) {
			$this->success("数据获取成功");
		}else{
			$this->error("数据获取失败");
		}
	}

}
